package com.keafmd.controller;

import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chenji
 * @date 2022/1/11 16:54
 */
@RestController
public class GlobalErrorController extends AbstractErrorController {

    public GlobalErrorController(ErrorAttributes errorAttributes) {
        super(errorAttributes);
    }


    @GetMapping(value = {"/error"})
    public String error(HttpServletRequest request) {
        HttpStatus httpStatus = super.getStatus(request);
        if(httpStatus.value()==200){
            return httpStatus.name();
        }else{
            return httpStatus.name();
        }
    }

    @Override
    @Deprecated
    public String getErrorPath() {
        return null;
    }
}
